import { AppAction, AppActionContext } from "@/context/app-context";
import { useContext } from "react";

function useAppAction<TSelector>(selector: (action: AppAction) => TSelector): TSelector;
function useAppAction(): AppAction;
function useAppAction<TSelector>(selector?: (action: AppAction) => TSelector) {
  const context = useContext(AppActionContext)
  if (!context) {
    throw new Error('AppActionContext 不存在')
  }
  if (!selector) {
    return context
  }
  return selector(context)
}

export default useAppAction